<template>
    <div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" @click="addLead()"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr>
                                    <th style="width: 70px">姓名</th>
                                    <th style="width: 90px">手机</th>
                                    <th style="width: 100px;">模糊信息</th>
                                    <th style="width: 200px;">模糊需求</th>
                                    <th>来源</th>
                                    <th>线索池</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="item in leadData">
                                    <td>
                                        {{item.name}}
                                    </td>
                                    <td>
                                        {{item.phone}}
                                    </td>
                                    <td>
                                        {{item.company}}
                                    </td>
                                    <td>
                                        {{item.leadsDetail}}
                                    </td>
                                    <td>
                                        {{item.clientSource}}
                                    </td>
                                    <td>
                                        {{getPool(item.leadsPool)}}
                                    </td>
                                    <td class="td-manage">
                                        <a title="编辑" class="layui-btn" @click.stop="openedit(item)" href="javascript:;">
                                            <i class="layui-icon">&#xe642;</i>
                                        </a>&nbsp
                                        <a title="作废" class="layui-btn layui-btn-danger" @click="drop(item.id,item.name)" href="javascript:;">
                                            <i class="layui-icon">作废</i>
                                        </a>
                                        <a title="领取" class="layui-btn layui-btn-warm" @click="openTake(item)" href="javascript:;">
                                            <i class="layui-icon">领取</i>
                                        </a>
                                    </td>

                                </tr>
                                </tbody>
                            </table>
                            <my-page :total="count"></my-page>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

    import { mapActions, mapState } from "vuex";
    import leadedit from './lead-edit';
    import page from './pagination2'
    import leadadd from './lead-add'
    import leadlog from './leadtakelog'

    export default {
        data(){
            return{
            }
        },
        name: "lead-list",
        components:{
            'my-page':page
        },
        created() {
            this.getleads();
            this.getleadsCounts();
        },
        computed:{
            ...mapState({
                leadData:state=>state.leadData,
                count:state=>state.leadCount,
            })
        },
        methods:{
            getPool(poolid){
                if(poolid === "1"){
                    return "文化纸线索池"
                }
                if(poolid === "2"){
                    return  "包装纸线索池"
                }
            },
            member_del(obj,id,client){
                let vm = this
                layer.confirm('确认删除 '+client+' ？',function(){
                    vm.deletelead(id);
                    setTimeout(vm.getleads,500);
                    setTimeout(vm.getleadsCounts,500);
                });
            },
            drop(id,name){
                let vm = this;
                layer.confirm('确认要作废 '+name+' ？ （可在作废区恢复）',function(){
                    vm.droplead(id);
                    setTimeout(vm.getdropleads,500);
                    setTimeout(vm.getleadsDropCounts,500);
                });

            },
            openedit(item){
                this.$layer.open({
                    id:1,
                    type:2,
                    content: {
                        content: leadedit, //传递的组件对象
                        parent: this,//当前的vue对象
                        data:{singleLead:item}//props
                    },
                    area:['800px','600px'],
                    title: '编辑 '+item.name+' 的用户信息',
                    maxmin: true,
                });
            },
            addLead(){
                this.$layer.open({
                    id:1,
                    type:2,
                    content: {
                        content: leadadd, //传递的组件对象
                        parent: this,//当前的vue对象
                    },
                    area:['800px','600px'],
                    title: '添加新用户',
                    maxmin: true,
                });
            },
            openTake(item){
                this.$layer.open({
                    id:1,
                    type:2,
                    content: {
                        content: leadlog, //传递的组件对象
                        data:{singleLead:item}//props
                    },
                    area:['600px','300px'],
                    title: '领取线索',
                    maxmin: true,
                });
            },
            ...mapActions(["getleads","getleadsCounts","deletelead","droplead"])
        },
        mounted(){
        },
    }


</script>

<style scoped>

</style>